package com.juzhencms.apps.busi.web;

import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.juzhencms.apps.busi.service.MenuService;
import com.juzhencms.apps.busi.service.NewsService;
import com.juzhencms.apps.busi.service.UserService;
import com.juzhencms.apps.common.tread.TreadTasks;
import com.juzhencms.apps.base.busi.service.UploadService;
import com.juzhencms.apps.base.busi.service.UploadService.UploadResult;
import com.juzhencms.apps.base.common.config.Config;
import com.juzhencms.apps.base.common.database.DBTable;
import com.juzhencms.apps.base.common.util.HtmlUtil;
import com.juzhencms.apps.base.common.util.ImageUtil;
import com.juzhencms.apps.base.common.util.StringUtil;
import com.juzhencms.apps.base.common.util.WebUtil;

import lombok.extern.slf4j.Slf4j;

@Controller
@RequestMapping("/newsLib")
@Slf4j
public class NewsLibController  extends BaseController{
	
	 @Autowired
	 private NewsService newsService;
	 
	 @Autowired
	 private UploadService uploadService;
	
	 @Autowired
	 private TreadTasks treadTasks;
	
	@RequestMapping(value="/gridlistData",produces="text/html; charset=UTF-8")
	@ResponseBody
	public String gridlistData(HttpServletRequest request){
		Map data=new HashMap();
		List whereParamList=new ArrayList();
		String where="where del_flag=0 ";
		
		//限定展示的数据范围
		if(request.getParameter("dataRange")!=null && !request.getParameter("dataRange").toString().trim().equals("")){
			if(request.getParameter("dataRange").equals("myorg")) {//本部门数据
				//默认查看本部门的数据
				where+=" and org_id = ? ";
				whereParamList.add(this.getLoginUser().getOrgId());
				
				//log.info("getOrgId:"+this.getLoginUser().getOrgId());
				
				
			}else if(request.getParameter("dataRange").equals("useable")) {//全部可用数据，本部门+其他部门的公开数据
				where+=" and (org_id = ? or share=1) ";
				whereParamList.add(this.getLoginUser().getOrgId());
			}else if(request.getParameter("dataRange").equals("suborg")){//下级部门数据
				where+=" and org_id != ? and org_id in("+this.getLoginUser().getSubOrgIds()+") ";
				whereParamList.add(this.getLoginUser().getOrgId());
			}
		}else {
			//默认查看本部门的数据
			where+=" and org_id = ? ";
			whereParamList.add(this.getLoginUser().getOrgId());
		}
		
		
		
		//搜索参数
		String searchVar=null;
		String varValue=null;
		if(request.getParameter("varValue")!=null && !request.getParameter("varValue").toString().trim().equals("")){
			
			if(request.getParameter("searchVar")!=null && !request.getParameter("searchVar").toString().trim().equals("")){
				searchVar=request.getParameter("searchVar");
				if("create_user".equals(searchVar)){
					varValue=request.getParameter("varValue");
					Map record=this.getCommonService().getJdbcDao().queryRow("select id from "+DBTable.user+" where user=?",new Object[]{varValue});	
					if(record != null){
						where += " and create_user = " + record.get("id");
					}else{
						data.put("data", "");
						return WebUtil.resultString(data,request);
					}
				}else{
					whereParamList.add("%"+request.getParameter("varValue")+"%");
					where += " and "+searchVar+" like ? ";
				}
				
			}else{
				whereParamList.add("%"+request.getParameter("varValue")+"%");
				where+=" and name like ? ";
			}
		}
		//搜索参数
		if(request.getParameter("menu_id")!=null && !request.getParameter("menu_id").toString().trim().equals("")){
			where+=" and menu_id = ? ";
			whereParamList.add(request.getParameter("menu_id"));
		}
		if(request.getParameter("name")!=null && !request.getParameter("name").toString().trim().equals("")){
			where+=" and name like ? ";
			whereParamList.add("%"+request.getParameter("name")+"%");
		}
		
		if(request.getParameter("publish")!=null && !request.getParameter("publish").toString().trim().equals("")){
			where+=" and publish = ? ";
			whereParamList.add(request.getParameter("publish"));
		}
		if(request.getParameter("recommend")!=null && !request.getParameter("recommend").toString().trim().equals("")){
			where+=" and recommend = ? ";
			whereParamList.add(request.getParameter("recommend"));
		}
		if(request.getParameter("is_comment")!=null && !request.getParameter("is_comment").toString().trim().equals("")){
			where+=" and is_comment = ? ";
			whereParamList.add(request.getParameter("is_comment"));
		}
		if(request.getParameter("is_exam")!=null && !request.getParameter("is_exam").toString().trim().equals("")){
			where+=" and is_exam = ? ";
			whereParamList.add(request.getParameter("is_exam"));
		}
		if(request.getParameter("is_vote")!=null && !request.getParameter("is_vote").toString().trim().equals("")){
			where+=" and is_vote = ? ";
			whereParamList.add(request.getParameter("is_vote"));
		}
		
		if(request.getParameter("check_status")!=null && !request.getParameter("check_status").toString().trim().equals("")) {
			where+=" and check_status = ? ";
			whereParamList.add(request.getParameter("check_status"));
		}
		
		//分类筛选条件，查询下级所有分类
		if(request.getParameter("category_id")!=null && StringUtil.isNotNullOrEmpty(request.getParameter("category_id").toString().trim()) && !request.getParameter("category_id").equals("0")){
			int category_id=Integer.parseInt(request.getParameter("category_id"));
			List ids=newsService.getSubCategoryIds(category_id);
			ids.add(category_id);
			
			List paramStr=new ArrayList();
			for(int i=0;i<ids.size();i++) {
				paramStr.add("?");
				whereParamList.add(ids.get(i));
			}
			
			where+=" and category_id in("+org.apache.commons.lang3.StringUtils.join(paramStr, ",")+") ";
		}
		
		/*if(request.getParameter("create_time_from")!=null && !request.getParameter("create_time_from").toString().trim().equals("")){
			where+=" and create_time >= ? ";
			whereParamList.add(request.getParameter("create_time_from"));
		}
		
		if(request.getParameter("create_time_to")!=null && !request.getParameter("create_time_to").toString().trim().equals("")){
			where+=" and create_time <= ? ";
			whereParamList.add(request.getParameter("create_time_to"));
		}*/
		
		//分页处理
		int pageIndex=1;
		if(request.getParameter("pageIndex")!=null && !request.getParameter("pageIndex").toString().trim().equals("")){
			pageIndex=new Integer(request.getParameter("pageIndex")).intValue();
		}
		int pageSize=10;
		if(request.getParameter("pageSize")!=null && !request.getParameter("pageSize").toString().trim().equals("")){
			pageSize=new Integer(request.getParameter("pageSize")).intValue();
		}
		int start=0;
		if(pageIndex>1){
			start=(pageIndex-1)*pageSize;
		}
		whereParamList.add(start);
		whereParamList.add(pageSize);
		
		//排序参数 
		String sortField="create_time";
		String sortOrder="desc";
		if(request.getParameter("sortField")!=null && !request.getParameter("sortField").equals(""))
			sortField = request.getParameter("sortField");
		if(request.getParameter("sortOrder")!=null && !request.getParameter("sortOrder").equals(""))
			sortOrder = request.getParameter("sortOrder");
		
		//查询列表数据
		List dataList=this.getCommonService().getJdbcDao().querySql("select id,name,hits,publish,recommend,position,create_user,create_time,update_time,share,image,org_id,org_name from "+DBTable.news+" "+where+" order by position asc,"+sortField+" "+sortOrder+",id desc limit ?,?", whereParamList.toArray());
		//log.info("select id,name,hits,publish,recommend,position,create_user,create_time from "+DBTable.news+" "+where+" order by "+sortField+" "+sortOrder+",create_time desc,id desc limit ?,?");
		//log.info(JSON.toJSONString(whereParamList));
		
		if(dataList!=null && dataList.size()>0){
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			for(int i=0;i<dataList.size();i++){
				Map row=(Map)dataList.get(i);
				Date date = (Date)row.get("create_time");
				row.put("create_time",sdf.format(date));
				
				date = (Date)row.get("update_time");
				row.put("update_time",sdf.format(date));
				
				if(StringUtil.isNotNullOrEmpty(row.get("image"))) {
					row.put("_image",Config.getUploadUrlPath()+"/"+row.get("image"));
				}else {
					row.put("_image",Config.getUploadUrlPath()+"/nophoto.jpg");
				}
				/*//查询所属部门
				Map org=this.getCommonService().getJdbcDao().queryRow("select name from "+DBTable.organization+" where id=? ", new Object[] {row.get("org_id")});
				if(org!=null) {
					row.put("org_name",org.get("name"));
				}*/
			}
		}
		
		//查询总条数
		Map countRow=this.getCommonService().getJdbcDao().queryRow("select count(id) as count_num from "+DBTable.news+" "+where, whereParamList.subList(0, whereParamList.size()-2).toArray());
		int recordsTotal=0;
		if(countRow.get("count_num")!=null){
			recordsTotal=new Integer(countRow.get("count_num").toString()).intValue();
		}
		
		//拼装返回的数据
		data.put("data", dataList.toArray());
		data.put("itemsCount", recordsTotal);
		
		return WebUtil.resultString(data,request);
	}
	
	@RequestMapping(value="/detailData/{id}",produces="text/html; charset=UTF-8")
	@ResponseBody
	public String detailData(@PathVariable("id") String id,HttpServletRequest request){
		Map data=new HashMap();
		Map record=this.getCommonService().getJdbcDao().queryRow("select id,name,subname,link_url,large_image,image,video,file,keywords,description,hits,digs,author,source,seo_keywords,seo_description,publish,recommend,share,index_recommend,recommend_location,content,video,video_code,create_time,category_id,org_id,org_name from "+DBTable.news+" where id=?",new Object[]{id});	
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date = (Date)record.get("create_time");
		record.put("create_time",sdf.format(date) );
		data.put("data", record);
		
		//log.info(JSON.toJSONString(record));
		
		//获取最新版本数据
		Map lastHistory=this.getDataHistoryService().getLastValidVersion(DBTable.news, Integer.parseInt(id));
		if(lastHistory!=null) {
			if(lastHistory.get("params")!=null) {
				//使用最新的版本字段替换掉当前主表字段进行显示
				Map param=JSON.parseObject(lastHistory.get("params").toString(),Map.class);
				if(param!=null) {
					for(Object key : param.keySet()) {
						if(param.get(key)!=null) {
							record.put(key, param.get(key));
						}
					}
				}
				lastHistory.remove("params");
			}
			data.put("lastHistory", lastHistory);
		}
		
		//log.info(JSON.toJSONString(record));
		
		if(record.get("content")!=null) {
			data.put("previewContent", this.getDataHistoryService().removeEditMark(record.get("content").toString()));
		}
		
		return WebUtil.resultString(data,request);
	}
	
	@RequestMapping(value="/save",produces="text/html; charset=UTF-8")
	@ResponseBody
	public String save(HttpServletRequest request) throws ParseException{
		
		boolean draft=false;
		
		if(request.getParameter("draft")!=null && request.getParameter("draft").equals("1")) {
			draft=true;
		}
		//System.out.println(request.getParameter("data"));
		Map data = JSON.parseObject(request.getParameter("data"), Map.class); 
		data.put("del_flag", 0);
		//LogTool.print(data, this.getClass());
		int id=0;
		if(data.get("id")!=null){
			id=new Long(data.get("id").toString()).intValue();
		}
		/*//如果主题图片不为空，缩略图为空，则自动生成缩略图 
		if(data.get("large_image")!=null && !data.get("large_image").equals("")){
			if(data.get("image")==null || data.get("image").equals("")){
				//生成缩略图
				String preName="s_";//缩略图文件名前缀
            	File smallImgFile=ImageUtil.thumbnailImage(new File(this.getCommonService().getConfig().getUploadFilePath()+"/"+data.get("large_image")),400,300, "s_", "cut");
            	if(smallImgFile!=null){
            		String smallImg=data.get("large_image").toString().replace(new File(data.get("large_image").toString()).getName(),smallImgFile.getName());
                	data.put("image", smallImg);
            	}
			}
		}*/
		//敏感词检查
		String sensitiveKeywords=this.filterSensitiveKeywords(DBTable.news, data);
		if(sensitiveKeywords!=null) {
			Map result=new HashMap();
			result.put("result", 0);
			result.put("id", id);
			result.put("msg", "内容中包含敏感关键词:<font style='color:#F00'>"+sensitiveKeywords+"</font>,请修改后再提交");
			return WebUtil.resultString(result,request);
		}
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date = new Date();
		
		//创建时间
		if(data.get("create_time")==null || data.get("create_time").equals("")){
			data.put("create_time", sdf.format(date));
		}
		
		//更新时间
		data.put("update_time", sdf.format(date));
		
		//使用创建时间的时间戳作为排序位置,另外为了避免重复增加当前时间戳毫秒数
		//long position=sdf.parse(data.get("create_time").toString()).getTime()+date.getTime()%1000;
		//data.put("position", 999);
		
		//执行图片本地化
		if(data.get("content")!=null) {
			String html=data.get("content").toString();
			Set<String> imgs=HtmlUtil.getImgStr(html);
			boolean replaceImg=false;
			for(String imgUrl:imgs) {
				if(imgUrl.indexOf(Config.getUploadUrlPath())!=0){
					//执行图片本地化
					UploadResult uploadResult=uploadService.uploadFileByUrl(imgUrl);
					if(uploadResult.getResult()==1) {
						//替换图片url
						html=html.replace(imgUrl, uploadResult.getUrlPath());
						replaceImg=true;
					}
					
				}
			}
			if(replaceImg) {
				data.put("content", html);
			}
		}
		
		//log.info(JSON.toJSONString(data));

		if(id==0){
			if(draft) {
				id=this.getDataHistoryService().saveDraftData(DBTable.news, data,"newsLib");
			}else {
				id=this.getDataHistoryService().saveCheckData(DBTable.news, data,"newsLib");
			}
			
			data.put("id", id);
		}else{
			if(draft) {
				this.getDataHistoryService().saveDraftData(DBTable.news, data,"newsLib");
			}else {
				this.getDataHistoryService().saveCheckData(DBTable.news, data,"newsLib");
			}
		}
		
		//this.treadTasks.startUpdateWeixinNewsSource();
		
		
		Map result=new HashMap();
		result.put("result", 1);
		result.put("id", id);
		result.put("msg", "保存成功");
		
		return WebUtil.resultString(result,request);
		
	}

	@RequestMapping(value="/delete",produces="text/html; charset=UTF-8")
	@ResponseBody
	public String delete(HttpServletRequest request){

		Map data = JSON.parseObject(request.getParameter("data"), Map.class); 
		
		String id=null;
		if(data.get("id")!=null){
			id=data.get("id").toString();
		}
		
		
		if(id==null || id.equals("")){
		}else{	
	        String[] idArray = id.split(",");
	        /*String tmpVar="?";
	        if(idArray!=null && idArray.length>0){
	        	Matcher matcher = Pattern.compile("\\d+").matcher(id);
	        	tmpVar=matcher.replaceAll("?");
	        }
			//this.getCommonService().getJdbcDao().updateSql("delete from "+DBTable.news+" where id in ("+tmpVar+")",idArray);
	        this.getCommonService().getJdbcDao().updateSql("update "+DBTable.news+" set del_flag=1 where id in ("+tmpVar+")",idArray);
	        */
	        
	        for(int i=0;i<idArray.length;i++) {
	        	String value=idArray[i];
	        	if(value!=null && !value.equals("")) {
	        		this.getDataHistoryService().deleteData(DBTable.news, Integer.parseInt(value));
	        		//删除微信中的素材
		        	this.treadTasks.startUpdateWeixinNewsSource(new Integer(value), true);
		        	////同时删除掉和此条新闻有关的自定义回复
		        	String sql="UPDATE "+DBTable.appReply+" set del_flag=1 where reply_message_type='news' and reply_content=? ";
		        	this.getCommonService().getJdbcDao().updateSql(sql,new Object[] {value});
	        	}
	        }
	        
		}
		Map result=new HashMap();
		result.put("result",1);
		result.put("msg", "操作成功");
		
		return WebUtil.resultString(result,request);
	}
	//更新排序
	@RequestMapping(value="/updatePosition",produces="text/html; charset=UTF-8")
	@ResponseBody
	public String updatePosition(HttpServletRequest request){
		this.getCommonService().getJdbcDao().updateSql("update "+DBTable.news+" set position=? where id=?",new Object[]{request.getParameter("position"),request.getParameter("id")});
		Map result=new HashMap();
		result.put("result",1);
		result.put("msg", "操作成功");
		
		return WebUtil.resultString(result,request);
	}
	
	@RequestMapping(value="/upAutoPosition",produces="text/html; charset=UTF-8")
	@ResponseBody
	public String upAutoPosition(HttpServletRequest request){
		
		String id=request.getParameter("id");
		String menuId=request.getParameter("menu_id");
		
		//查询当前新闻
		Map thisNews=this.getCommonService().getJdbcDao().queryRow("select id,menu_id,recommend,position from "+DBTable.news+" where id=?", new Object[] {id});
		
		//查询上一条新闻
		Map prevNews=this.getCommonService().getJdbcDao().queryRow("select id,menu_id,recommend,position from "+DBTable.news+" where menu_id=? and recommend=? and position>=? and id!=? and del_flag=0 order by position asc limit 0,1", new Object[] {menuId,thisNews.get("recommend"),thisNews.get("position"),id});
		
		if(prevNews!=null) {
			//如果两条数据的排序位置相差超过2，则交换并且减1，以避免有排序号重复的数据
			if(Long.parseLong(prevNews.get("position").toString())-Long.parseLong(thisNews.get("position").toString())>2) {
				
				this.getCommonService().getJdbcDao().updateSql("update "+DBTable.news+" set position=? where id=?",new Object[]{Long.parseLong(prevNews.get("position").toString())-1,thisNews.get("id")});
				this.getCommonService().getJdbcDao().updateSql("update "+DBTable.news+" set position=? where id=?",new Object[]{Long.parseLong(thisNews.get("position").toString())+1,prevNews.get("id")});
				
				
			}else {//否则交换排序号
				this.getCommonService().getJdbcDao().updateSql("update "+DBTable.news+" set position=? where id=?",new Object[]{Long.parseLong(prevNews.get("position").toString()),thisNews.get("id")});
				this.getCommonService().getJdbcDao().updateSql("update "+DBTable.news+" set position=? where id=?",new Object[]{Long.parseLong(thisNews.get("position").toString()),prevNews.get("id")});
				
			}
		}
		
		
		
		
		
		
		
		Map result=new HashMap();
		result.put("result",1);
		result.put("msg", "操作成功");
		
		return WebUtil.resultString(result,request);
	}
	
	@RequestMapping(value="/downAutoPosition",produces="text/html; charset=UTF-8")
	@ResponseBody
	public String downAutoPosition(HttpServletRequest request){
		String id=request.getParameter("id");
		String menuId=request.getParameter("menu_id");
		
		//查询当前新闻
		Map thisNews=this.getCommonService().getJdbcDao().queryRow("select id,menu_id,recommend,position from "+DBTable.news+" where id=?", new Object[] {id});
		
		//查询上一条新闻
		Map nextNews=this.getCommonService().getJdbcDao().queryRow("select id,menu_id,recommend,position from "+DBTable.news+" where menu_id=? and recommend=? and position<=? and id!=? and del_flag=0 order by position desc limit 0,1", new Object[] {menuId,thisNews.get("recommend"),thisNews.get("position"),id});
		
		
		if(nextNews!=null) {
			//如果两条数据的排序位置相差超过2，则交换并且减1，以避免有排序号重复的数据
			if(Long.parseLong(thisNews.get("position").toString())-Long.parseLong(nextNews.get("position").toString())>2) {
				
				this.getCommonService().getJdbcDao().updateSql("update "+DBTable.news+" set position=? where id=?",new Object[]{Long.parseLong(nextNews.get("position").toString())+1,thisNews.get("id")});
				this.getCommonService().getJdbcDao().updateSql("update "+DBTable.news+" set position=? where id=?",new Object[]{Long.parseLong(thisNews.get("position").toString())-1,nextNews.get("id")});
				
				
			}else {//否则交换排序号
				this.getCommonService().getJdbcDao().updateSql("update "+DBTable.news+" set position=? where id=?",new Object[]{Long.parseLong(nextNews.get("position").toString()),thisNews.get("id")});
				this.getCommonService().getJdbcDao().updateSql("update "+DBTable.news+" set position=? where id=?",new Object[]{Long.parseLong(thisNews.get("position").toString()),nextNews.get("id")});
				
			}
		}
		
		Map result=new HashMap();
		result.put("result",1);
		result.put("msg", "操作成功");
		
		return WebUtil.resultString(result,request);
	}
	
	//更新发布状态
	@RequestMapping(value="/updatePublish",produces="text/html; charset=UTF-8")
	@ResponseBody
	public String updatePublish(HttpServletRequest request){
		String num = "1".equals(request.getParameter("publish"))?"0":"1";
		this.getCommonService().getJdbcDao().updateSql("update "+DBTable.news+" set publish=? where id=?",new Object[]{num,request.getParameter("id")});
		Map result=new HashMap();
		result.put("result",1);
		result.put("msg", "操作成功");
		
		return WebUtil.resultString(result,request);
	}
	@RequestMapping(value="/updateShare",produces="text/html; charset=UTF-8")
	@ResponseBody
	public String updateShare(HttpServletRequest request){
		String num = "1".equals(request.getParameter("share"))?"0":"1";
		this.getCommonService().getJdbcDao().updateSql("update "+DBTable.news+" set share=? where id=?",new Object[]{num,request.getParameter("id")});
		Map result=new HashMap();
		result.put("result",1);
		result.put("msg", "操作成功");
		
		return WebUtil.resultString(result,request);
	}
	
	
	//更新推荐状态
	@RequestMapping(value="/updateRecommend",produces="text/html; charset=UTF-8")
	@ResponseBody
	public String updateRecommend(HttpServletRequest request){
		String num = "1".equals(request.getParameter("recommend"))?"0":"1";
		
		
		/*long position=0;
		if(num.equals("1")) {
			//将排序位设置为当前栏目第一位
			Map tmpNews=this.getCommonService().getJdbcDao().queryRow("select id,position,create_time from "+DBTable.news+" where menu_id=? order by position desc,create_time desc limit 0,1", new Object[] {request.getParameter("menu_id")});
			position=Long.parseLong(tmpNews.get("position").toString())+10;
		}else {
			//将排序位设置为出创建时间
			Map tmpNews=this.getCommonService().getJdbcDao().queryRow("select id,position,create_time from "+DBTable.news+" where id=? ", new Object[] {request.getParameter("id")});
			position=((Date)tmpNews.get("create_time")).getTime()+(int)Math.random()*500;
		}*/
		this.getCommonService().getJdbcDao().updateSql("update "+DBTable.news+" set recommend=? where id=?",new Object[]{num,request.getParameter("id")});
		
		/*log.info("update "+DBTable.news+" set recommend=?,position=? where id=?");
		log.info(num+","+position+","+request.getParameter("id"));*/
		
		Map result=new HashMap();
		result.put("result",1);
		result.put("msg", "操作成功");
		return WebUtil.resultString(result,request);
	}
	
	/*//复制新闻
	@RequestMapping(value="/copyToMenu",produces="text/html; charset=UTF-8")
	@ResponseBody
	public String copyToMenu(HttpServletRequest request){
		
		
		String id=request.getParameter("id");
		String menus=request.getParameter("menus");
		
		if(id==null || id.equals("") || menus==null || menus.equals("")){
			Map result=new HashMap();
			result.put("result",0);
			result.put("msg", "参数错误");
			return WebUtil.resultString(result,request);
		}
		
		//获取新闻数据
		Map news=this.getCommonService().getJdbcDao().queryRow("select * from "+DBTable.news+" where id=?", new Object[]{id});
		news.remove("id");
		//获取新闻图集
		List photosList = this.getCommonService().getJdbcDao().querySql("select menu_id,data_id,`name`,image,hits,position,publish,`status`,create_user,create_time,update_user,update_time from "+DBTable.photos+" where data_id=?  AND del_flag=0", new Object[]{id});
		
		String[] menuArr=menus.split(",");
		String tmpVar="?";
        if(menuArr!=null && menuArr.length>0){
        	Matcher matcher = Pattern.compile("\\d+").matcher(menus);
        	tmpVar=matcher.replaceAll("?");
        }
        List menuList=this.getCommonService().getJdbcDao().querySql("select id,site_id from "+DBTable.menu+" where id in("+tmpVar+")", menuArr);
		
        if(menuList!=null){
        	for(int i=0;i<menuList.size();i++){
        		Map menu=(Map)menuList.get(i);
        		news.put("menu_id",menu.get("id"));
        		news.put("site_id",menu.get("site_id"));
				int newId=this.getCommonService().getJdbcDao().addObj(DBTable.news, news);
				//Map newsId = this.getCommonService().getJdbcDao().queryRow("select max(id) as id  from "+DBTable.news);
				//Map newsId = this.getCommonService().getJdbcDao().queryRow(" SELECT LAST_INSERT_ID() as id ");

				if (photosList !=null && photosList.size()>0 ) {
					for (int j = 0; j < photosList.size(); j++) {
						Map photos = (Map)photosList.get(j);
						photos.put("data_id", newId);
						this.getCommonService().getJdbcDao().addObj(DBTable.photos, photos);
					}
					
				}
				
        	}
        }
		
		Map result=new HashMap();
		result.put("result",1);
		result.put("msg", "复制成功");
		
		return WebUtil.resultString(result,request);
	}*/	
}
